<?php
/**
 * 数组重新按某一索引进行分组
 * @param $array
 * @param $filed
 * @return array
 */
function group_array($array,$filed){
    $new = [];
    foreach ($array as $key=>$value){
        $new[$value[$filed]][] = $value;
    }
    return $new;
}
/**
 * 递归实现无限极分类列表
 * @param $data
 * @param string $name
 * @param int $parent_id
 * @param int $level
 * @return array
 */
function getTree($data, $name='', $parent_id=0, $level = 0){
    static $tree = array();
    foreach ($data as $key => $value) {
        if ($value['parent_id'] == $parent_id) {
            $value[$name] = str_repeat('— ',$level * 1) . $value[$name];
            $tree[] = $value;
            unset($data[$key]);
            getTree($data, $name, $value['id'], $level + 1);
        }
    }
    return $tree;
}